package cn.com.wxd.service.weather;

import java.util.ArrayList;
import java.util.List;

/**
 * 保存天气数据的缓存
 * @author wangxudong
 *
 */
public class WeatherCache {
	private String weatherData = null;
	private List<Weatherbean> weathers = null;
	private static WeatherCache weatherCahce = null;
	
	private WeatherCache(){
		weatherData = "";
		weathers = new ArrayList<Weatherbean>();
	}
	/**
	 * 获取当前实例
	 * @return
	 */
	public static WeatherCache getInstance(){
		if(weatherCahce==null){
			weatherCahce = new WeatherCache();
		}
		return weatherCahce;
	}
	
	/**
	 * 根据省份名称从缓存中获取当前的天气信息
	 * @param quName
	 * @return
	 */
	public Weatherbean getWeatherCache(String quName) {
		for (int i = 0; i < weathers.size(); i++) {
			if(quName.equalsIgnoreCase(weathers.get(i).getQuName())){
				return weathers.get(i);
			}
		}
		return null;
	}

	/**
	 * 在缓存中添加一个访问过的天气信息
	 * @param weatherBean
	 */
	public void setWeatherCache(Weatherbean weatherBean) {
		this.weathers.add(weatherBean);
	}
	
	/**
	 * 获取天气数据
	 * @return
	 */
	public String getWeatherData() {
		return weatherData;
	}

	/**
	 * 设置天气数据,重设天气信息数据
	 * @param weatherData
	 */
	public void setWeatherData(String weatherData) {
		//重设该缓存的时候，刷新其他数据缓存。
		if(weathers!=null){
			weathers.clear();
		}else{
			weathers = new ArrayList<Weatherbean>();
		}
		this.weatherData = weatherData;
	}
}
